package main

import "fmt"

func main() {
	m := map[string]string{
		"name":    "ccmouse",
		"course":  "golang",
		"site":    "imooc",
		"quality": "not bad",
	}
	fmt.Println(m)

	// m2 == empty map
	m2 := make(map[string]int)
	fmt.Println(m2)

	// m3 == nil
	var m3 map[string]int
	fmt.Println(m3)

	fmt.Println("Traversing map")
	for k, v := range m {
		fmt.Println(k, v)
	}

	fmt.Println("Getting values")
	courseName, ok := m["course"]
	fmt.Println(courseName, ok)
	//key如果拼错了呢？==>不会报错，会拿到zerovalue
	if causeName, ok := m["cause"]; ok {
		fmt.Println(causeName)
	} else {
		fmt.Println("key does not exist")
	}

	fmt.Println("Deleting values")
	//这里虽然ok上面定义了，但是name没有定义，所以仍可以用:=
	name, ok := m["name"]
	fmt.Println(name, ok)

	delete(m, "name")

	//name和ok上面都定义过了，所以不能用:=
	name, ok = m["name"]
	fmt.Println(name, ok)

}
